<?php
error_reporting(E_ALL^E_NOTICE);
header('Content-Type:text/html;charset=utf-8');
define('MINI_RUN', true);
$createSwitch='install.off';
if (file_exists($createSwitch)) exit('数据库已创建，请先删除install目录下的create.off文件再重新执行本页面。<br />');

require ('../file.php');
require ('../core/MysqlPDO.class.php');

$pdo=new MysqlPDO();
//创建数据表
$sqlstrings="DROP TABLE IF EXISTS `Mini_Admin`;
create table `Mini_Admin`
(
`AdminId` tinyint(4) unsigned AUTO_INCREMENT,
`UserName` varchar(50) NOT NULL,
`Password` char(32) NOT NULL,
MiniCode char(32) NOT NULL,
`NickName` varchar(50) NOT NULL,
`RoleId` tinyint(4) unsigned NOT NULL,
`CreateTime` timestamp default current_timestamp,
PRIMARY KEY (`AdminId`)
)ENGINE=MyISAM charset=utf8;

INSERT INTO `Mini_Admin` values(NULL,'mini2011','eaff4313802c56a4d431841d83c4b502','chaoyue','mini2011',3,now());
INSERT INTO `Mini_Admin` values(NULL,'xiaojun','bcd1e1893518ef0e4925f5df7fda2422','910617','小君',3,now());


create table `Mini_Class`
(
`ClassId` tinyint(4) unsigned AUTO_INCREMENT,
`ClassName` varchar(50) NOT NULL UNIQUE,
`ClassDir` varchar(50) NOT NULL UNIQUE,
`ParentId` tinyint(4) unsigned NOT NULL DEFAULT 0,
`ClassTempId` tinyint(4) unsigned NOT NULL,
`PageTempId` tinyint(4) unsigned NOT NULL,
`ClassKey` varchar(600) NOT NULL,
`ClassDesc` varchar(600) NOT NULL,
`ClassCss` varchar(1000) NOT NULL,
`ClassJs` varchar(1000) NOT NULL,
`SmallText` text NOT NULL,
`ClassText` text NOT NULL,
`IsUpdate` bit NOT NULL default 1,
PRIMARY KEY (`ClassId`)
)ENGINE=MyISAM charset=utf8;

DROP TABLE IF EXISTS `Mini_ClassTemp`;
create table `Mini_ClassTemp`
(
`TempId` tinyint(4) unsigned AUTO_INCREMENT,
`TempName` varchar(50) NOT NULL UNIQUE,
`TempText` text NOT NULL,
PRIMARY KEY (`TempId`)
)ENGINE=MyISAM charset=utf8;

DROP TABLE IF EXISTS `Mini_Page`;
create table Mini_Page
(
`PageId` int unsigned AUTO_INCREMENT,
`ClassId` tinyint(4) unsigned unsigned NOT NULL,
`Title` varchar(200) NOT NULL,
`PageKey` varchar(600) NOT NULL,
`PageDesc` varchar(600) NOT NULL,
`Source` varchar(50) NOT NULL,
`Author` varchar(50) NOT NULL,
`UserId` tinyint(4) unsigned NOT NULL,
`PubTime` datetime NOT NULL,
`Click` int unsigned NOT NULL default 1,
`SmallText` text NOT NULL,
`PageText` text NOT NULL,
`Good` int unsigned NOT NULL default 0,
`Bad` int unsigned NOT NULL default 0,
`Score` int unsigned NOT NULL default 0,
`ScoreNum` int unsigned NOT NULL default 0, 
`FileName` varchar(50) NOT NULL,
`ModifyTime` timestamp default current_timestamp,
`IsUpdate` bit NOT NULL default 1, 
PRIMARY KEY (`PageId`),
KEY `ClassId` (`ClassId`),
KEY `UserId` (`UserId`),
KEY `PubTime` (`PubTime`)
)ENGINE=MyISAM charset=utf8;

DROP TABLE IF EXISTS `Mini_PageTemp`;
create table `Mini_PageTemp`
(
`TempId` tinyint(4) unsigned AUTO_INCREMENT,
`TempName` varchar(50) NOT NULL UNIQUE,
`TempText` text NOT NULL,
PRIMARY KEY (`TempId`)
)ENGINE=MyISAM charset=utf8;

DROP TABLE IF EXISTS `Mini_TagTemp`;
create table `Mini_TagTemp`
(
`TempId` tinyint(4) unsigned AUTO_INCREMENT,
`TempName` varchar(50) NOT NULL UNIQUE,
`TempText` text NOT NULL,
PRIMARY KEY (`TempId`)
)ENGINE=MyISAM charset=utf8;

DROP TABLE IF EXISTS `Mini_VarTemp`;
CREATE TABLE `Mini_VarTemp` (
`VarName` varchar(50) NOT NULL UNIQUE,
`VarInfo` varchar(200) NOT NULL,
`VarText` text NOT NULL
)ENGINE=MYISAM CHARSET=utf8;

DROP TABLE IF EXISTS `Mini_Data`;
create table `Mini_Data`
(
`ClassId` tinyint(4) unsigned NOT NULL,
`DataKey` varchar(50) not null unique ,
`DataValue` varchar(100) NOT NULL unique ,
`DataDesc` text not null
)ENGINE=MyISAM charset=utf8;

INSERT INTO `Mini_ClassTemp` VALUES (NULL,'默认栏目首页模板','');

INSERT INTO `Mini_Class` VALUES (NULL,'IT百事通','archive',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'时尚科技','tech',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'IT资料库','data',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'IT专题库','topic',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'主流语言教程','main',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'数据库教程','database',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'轻量级教程','light',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'其他教程','others',0,1,1,'','','','','','',default);
INSERT INTO `Mini_Class` VALUES (NULL,'心有灵犀','soul',0,1,1,'','','','','','',default);

INSERT INTO `Mini_PageTemp` VALUES (NULL,'默认栏目内容模板','');

INSERT INTO `Mini_TagTemp` VALUES (NULL,'默认标签模板','')

";
echo "获取sql文件数据...<br />";
$sqlstrings=str_replace("\r", "", $sqlstrings);
$sqlstrings=str_replace("\n", "", $sqlstrings);
$sql_array=explode(";", trim($sqlstrings));
foreach ($sql_array as $sql){
	$pdo->changeSQL($sql);	
}
createFile($createSwitch, "install=off");
echo "<br />初始化数据表完毕......！";
?>

